class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param numProject int整型 
     * @param groups int整型vector<vector<>> 
     * @return int整型vector
     */
    vector<int> findOrder(int numProject, vector<vector<int> >& groups) {
        int row=groups.size();
        int col=groups[0].size();
        vector<vector<int>> v(numProject);
        vector<int> result;
        int du[2010]={0};
        int sum=0;
        for(int i=0;i<row;i++){
            int first=groups[i][0];
            int second=groups[i][1];
            v[second].push_back(first);
            du[first]++;
        }
        queue<int> q;
        for(int i=0;i<numProject;i++){
            if(du[i]==0){
                q.push(i);
                sum++;
            }
        }
        while(q.size()){
            int t=q.front();
            result.push_back(t);
            q.pop();
            for(auto& e:v[t]){
                du[e]--;
                if(du[e]==0){
                    sum++;
                    q.push(e);
                }
            }
        }
        if(sum!=numProject) return vector<int>();
        else return result;
    }
};